﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using CodeDomHelper.Types;
using System.Diagnostics;

namespace CodeDomHelper.CodeDom
{

    [DebuggerDisplay("{Type}", Name = "MethodInvoke")]
    [Serializable()]
    [System.Diagnostics.DebuggerStepThrough()]
    public class MethodInvoke : CodeMethodInvokeExpression, IType
    {


        internal MethodInvoke(MethodExp method, params CodeExpression[] parameters)
            : base(method, parameters) 
        {
            this.MethodRoot = method;        
        }

        internal MethodInvoke(MethodExp method, TypeExp type, params CodeExpression[] parameters)
            : base(method, parameters)
        { 
            this.Type = new TypeExp(type);
            this.MethodRoot = method;
        }

        internal MethodInvoke(MethodExp method, string methodName, params CodeExpression[] parameters)
            : base(method, methodName, parameters) 
        {
            this.MethodRoot = method;
        }

        internal MethodInvoke(MethodExp method, string methodName, TypeExp type, params CodeExpression[] parameters)
            : base(method, methodName, parameters)
        {
            this.Type = new TypeExp(type);
            this.MethodRoot = method;
        }

        #region Property

        public PropertyExp Property(string propertyName, string typeName)
        {
            return new PropertyExp(this, propertyName, typeName);
        }

        public PropertyExp Property(string propertyName, TypeExp type)
        {
            return new PropertyExp(this, propertyName, type);
        }

        public PropertyExp Property(string propertyName, Type type)
        {
            return new PropertyExp(this, propertyName, type);
        }

        public PropertyExp Property(string propertyName, TypeExpression type)
        {
            return new PropertyExp(this, propertyName, type);
        }

        #endregion

        #region Field

        public FieldExp Field(string fieldName, string typeName)
        {
            return new FieldExp(this, fieldName, typeName);
        }

        public FieldExp Field(string fieldName, TypeExp type)
        {
            return new FieldExp(this, fieldName, type);
        }

        public FieldExp Field(string fieldName, Type type)
        {
            return new FieldExp(this, fieldName, type);
        }

        public FieldExp Field(string fieldName, TypeExpression type)
        {
            return new FieldExp(this, fieldName, type);
        }

        #endregion

        #region Method

        public MethodExp Method(string methodName)
        {
            return new MethodExp(this, methodName);
        }

        public MethodExp Method(string methodName, TypeExp typeReturn)
        {
            return new MethodExp(this, methodName, typeReturn);
        }

        #endregion

        public TypeExp Type { get; private set; }


        public MethodExp MethodRoot { get; set; }

        public CastExp As(TypeExp type)
        {
            return Helper.Cast(this, type);
        }

    }

}
